<?php
class CustomerModel extends Models
{
    protected $tableName='customer';

    public function getPassword($id)
    {
        if($result=$this->getModelAttributes($id, array('pwd'), $this->tableName)) return  isset($result['pwd']) ? $result['pwd'] : false;
        return false;
    }

    public function getDebt($id)
    {
        $orderModel=$this->model->load('orderModel');
        if(!$orders=$orderModel->findAllModelAttributesByAttributes(array('total','partial_paid'),array('customer_id'=>$id))) return 0;

        $debt=0;
        $partial=0;
        foreach($orders as $order){
            $debt+=$order['total'];
            $partial+=$order['partial_paid'];
        }

        return $debt-$partial;
    }

    private function getModelAttributes($id, $attributes)
    {
        return $this->findModelAttributesByPk($id, $attributes);
    }

    public function getTableName(){
        return $this->tableName;
    }
}